import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

import AtmSystem.*;

public class AdminDelectAccount extends HttpServlet
{
	public void doPost(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException
                {
                        String AccountName = request.getParameter("cardnumber");

                        BankAccountDBIO IO = new BankAccountDBIO();
                  

                        ServletContext sc;
					    sc = getServletContext();
                        String scr =sc.getRealPath("/") +"MyBankAccountDB.dat";
						BankAccountDB DB = IO.loadBankAccountDB(scr);
						ClientDBIO IOa = new ClientDBIO();
                        String scr1 =sc.getRealPath("/") +"MyClientDB.dat";
                        ClientDB client = IOa.loadClientDB(scr1);

                        
                 

                        if(DB.removeb(Integer.parseInt(AccountName)))
                        {
							for(int index=0;index<client.getNumbers();index++)
							{
							client.get(index).getBankAccountDB().removeb(Integer.parseInt(AccountName));
							}
                             IO.writerBankAccountDB(scr,DB);  
							 IOa.writerClientDB(scr1,client);    

                             response.sendRedirect("/AtmSystem/37.html");
		        }
                        else
                        {
                             response.sendRedirect("/AtmSystem/36.html");
                        }
                  }
}